import requests
def spider1():
    ## 输入要检索的内容
    words = input("输入要搜索的内容：")
    ## url地址
    url = "https://www.sogou.com/web"
    ## 传递get请求的参数
    param = {
        "query":words
    }
    ## 头部信息，User-Agent伪装
    headers = {
        "User-Agent":'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
    }
    ## 请求，把url、参数、和头部信息写进去
    response = requests.get(url=url,params=param,headers=headers)
    ## 输出请求的url地址
    print(response.url)
    ## 保存该词数据的html
    with open(words+".html","w+",encoding="utf-8") as f:
        f.write(response.text)
        f.close()
if __name__ == '__main__':
    spider1()